var postData = require('../data/post_data_list.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isPlay:true
  },


  onradioBtn:function(){
    var music = this.data.music;
    if(!this.data.isPlay){
      this.setData({
        isPlay: true
      });
      wx.pauseBackgroundAudio();
    }else{
      this.setData({
        isPlay: false
      });


      wx.playBackgroundAudio({
        dataUrl: music.musicUrl,
        title: music.title,
        coverImgUrl: music.musicImg
      })
    }
   
  },

  onshareTap:function(){
       wx.showActionSheet({
         itemList: ["分享到朋友圈","分享到qq","分享到微博"],
         success:function(res){
           console.log(res.tapIndex);
         }
       })
  },
  onCollectStatus:function(){
    var postsStatus = wx.getStorageSync("post-status-collect") || {},

        postStatus = postsStatus[this.data.postId] || false;
        self = this;
        postStatus = ! postStatus;
        postsStatus[this.data.postId] = postStatus;
       
        wx.showModal({
          title:"收藏" ,
          content: this.data.isCollect ? "取消收藏该文章" : "确认收藏该文章",
          success:function(res){
             if(res.confirm){
               wx.setStorageSync("post-status-collect", postsStatus);
               self.setData({
                 isCollect: postStatus
               });
             }
          }
        })
       

  },
  onLoad: function (options) {
    var postId = options.id,
        detaillData = postData[postId],
        music = detaillData.music;
      
        this.setData({
          detaillData,
          postId,
          music
        });
     var postsStatus = wx.getStorageSync("post-status-collect");
     if(!postsStatus){
       var postsStatus = {};
           postsStatus[postId]= false;
       wx.setStorageSync("post-status-collect",postsStatus);
     }else{
       var postStatus = postsStatus[postId];
          if(postStatus){
            this.setData({
              isCollect:postStatus
            })
          }
     }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
   
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.stopBackgroundAudio();

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})